<template>
  <div class="hello">
    <h1>当前求和是：{{ count }}</h1>
    <h3>当前求和是：{{ becomeTen }}</h3>
    <h3>人员总数是多少：{{ personList.length }}</h3>
    <div class="main">
      <select name="num" @change="change($event)">
        <option value="0">0</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
      </select>
      <button @click="decrement">+</button>
      <button @click="increment">-</button>
      <button @click="addOdd">当和为奇数再加</button>
      <button @click="addWait">等一下在加</button>
    </div>
  </div>
</template>

<script>
import { mapActions, mapGetters, mapState } from "vuex";
export default {
  name: "Count",
  data() {
    return {
      num: 0,
    };
  },
  methods: {
    ...mapActions("countMudle", [
      "decrement",
      "increment",
      "addOdd",
      "addWait",
    ]),
    // ...mapActions({
    //   decrement: "decrement",
    //   increment: "increment",
    //   addOdd: "addOdd",
    //   addWait: "addWait",
    // }),
    change(event) {
      this.$store.state.count = event.target.value;
    },

    //借助mapState生成计算属性，从state中读取数据。（对象写法）
  },
  computed: {
    // ...mapState({
    //   count: (state) => {
    //     return state.count;
    //   },
    //   becomeTen: (state) => {
    //     return state.count*10;
    //   },
    // }),
    ...mapState("countMudle", ["count", "becomeTen"]),
    ...mapState("personMudle", ["personList"]),
    // ...mapGetters({
    //   bigNum: "becomeTen",
    // }),
    ...mapGetters("countMudle", ["becomeTen"]),
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
button {
  height: 20px;
  width: 150px;
  margin: 5px;
}
.main {
  padding: 10px;
  margin: 10px;
}
select {
  margin: 10px;
}
</style>
